package net.whzjkj.gateway.core.manager;

import net.whzjkj.gateway.core.server.AbstractNettyServer;
import net.whzjkj.gateway.core.server.Server;
import net.whzjkj.gateway.core.util.SpringContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

/**
 * @description:
 * @author: Mr.Hu
 * @create: 2018-10-31 16:39
 **/
@Component
public class NettyServerManager {
    @Qualifier("tcpServer")
    @Autowired
    private AbstractNettyServer nettyServer;
    public NettyServerManager() {
       // nettyServer = SpringContextHolder.getBean(TcpServer.class);
    }
    public NettyServerManager(Server.TransmissionProtocol transmissionProtocol) {
        if (transmissionProtocol==Server.TRANSMISSION_PROTOCOL.UDP){
            nettyServer = SpringContextHolder.getBean(UdpServer.class);
        }else {
            nettyServer = SpringContextHolder.getBean(TcpServer.class);
        }
    }
    public void startServer(int port) throws Exception {

        nettyServer.startServer(port);
    }

    public void startServer() throws Exception {
        nettyServer.startServer();
    }

    public void stopServer() throws Exception {
        nettyServer.stopServer();
    }
}
